package mail

import (
	"crypto/tls"
	"github.com/gogf/gf/frame/g"
	"gopkg.in/gomail.v2"
)

//Send  发送邮件
func Send(subject, body string, address []string) error {
	host := g.Config().GetString("mail.host")
	port := g.Config().GetInt("mail.port")
	user := g.Config().GetString("mail.account")
	pwd := g.Config().GetString("mail.password")
	name := g.Config().GetString("mail.name")
	d := gomail.NewDialer(host, port, user, pwd)
	d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
	m := gomail.NewMessage()
	m.SetAddressHeader("From", user, name)
	m.SetHeader("Subject", subject)
	m.SetBody("text/plain", body)
	m.SetHeader("To", address...)
	err := d.DialAndSend(m)
	if err != nil {
		return err
	}
	return nil
}
